﻿using B.S.BaseData.Domain.Entities;
using B.S.BaseData.ErrorCode;
using B.S.BaseData.Infrastructure.Interfaces;
using B.S.BaseData.Read.API.Command.UserCommand;
using MediatR;

namespace B.S.BaseData.Read.API.CommandHandler.UserHandler
{
    public class GetUsersHandler : IRequestHandler<GetUsersCommand, APIResult<User>>
    {
        private readonly IBaseRepository<User> userRep;

        public GetUsersHandler(IBaseRepository<User> userRep)
        {
            this.userRep = userRep;
        }
        public Task<APIResult<User>> Handle(GetUsersCommand request, CancellationToken cancellationToken)
        {
            APIResult<User> result = new APIResult<User>();
            var a = userRep.GetAll().FirstOrDefault(x=>x.UserId==request.UserId);
            result.Msg = "显示成功";
            result.Code = APIEnum.Success;
            result.Data = a;
            return Task.FromResult(result);
        }
    }
}
